﻿using MessagePack;
using System.Runtime.Serialization;

namespace Manon.Core
{
    [MessagePackObject(true)]
    public class Result
    {
        /// <summary>
        /// 是否成功
        /// </summary> 
        public bool Success { get; set; }

        /// <summary>
        /// 状态码
        /// </summary> 
        public int StatusCode { get; set; }

        /// <summary>
        /// 返回信息
        /// </summary> 
        public string Message { get; set; }

        /// <summary>
        /// 统一响应编码
        /// </summary>
        public string Code { get; set; }



        public static Result Successed()
        {
            return new Result()
            {
                Success = true,
                StatusCode = 200,
                Message = "请求成功"
            };
        }

        public static Result Failed()
        {
            return new Result()
            {
                Success = false,
                StatusCode = 500,
                Message = "请求失败"
            };
        }

        public static Result Successed(string message)
        {
            return new Result()
            {
                Success = true,
                StatusCode = 200,
                Message = message
            };
        }

        public static Result Failed(string message)
        {
            return new Result()
            {
                Success = false,
                StatusCode = 500,
                Message = message
            };
        }
    }



    [MessagePackObject(true)]
    public class Result<T>
    {
        /// <summary>
        /// 是否成功
        /// </summary> 
        public bool Success { get; set; }

        /// <summary>
        /// 状态码
        /// </summary> 
        public int StatusCode { get; set; }

        /// <summary>
        /// 返回信息
        /// </summary> 
        public string Message { get; set; }

        /// <summary>
        /// 数据
        /// </summary>  
        public T Data { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static Result Successed()
        {
            return new Result()
            {
                Success = true,
                StatusCode = 200,
                Message = ""
            };
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static Result Failed()
        {
            return new Result()
            {
                Success = false,
                StatusCode = 500,
                Message = ""
            };
        }
         
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static Result Successed(string message)
        {
            return new Result()
            {
                Success = true,
                StatusCode = 200,
                Message = message
            };
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static Result Failed(string message)
        {
            return new Result()
            {
                Success = false,
                StatusCode = 500,
                Message = message
            };
        }


        public static Result<T> Successed(string message, T data)
        {
            return new Result<T>()
            {
                Success = true,
                StatusCode = 200,
                Message = message,
                Data = data
            };
        }

        public static Result<T> Failed(string message, T data)
        {
            return new Result<T>()
            {
                Success = false,
                StatusCode = 500,
                Message = message,
                Data = data
            };
        }

        public static Result<T> Successed(T data)
        {
            return new Result<T>()
            {
                Success = true,
                StatusCode = 200,
                Message = "请求成功!",
                Data = data
            };
        }

        public static Result<T> Failed(T data)
        {
            return new Result<T>()
            {
                Success = false,
                StatusCode = 500,
                Message = "请求失败",
                Data = data
            };
        }
    }


}
